import React, { Component } from 'react'
import './index.css';
import axios from 'axios';
export default class Goods extends Component {

    state = {
        goods: []
    }

    render() {

        return (
            <div className="container">
                <h2>商品列表</h2>
                <div className="goods-list">

                    {
                        this.state.goods.map(item => {
                            return <div className="item">
                                <div className="img">
                                    <img width="100%" src={'http://127.0.0.1:3002' + item.img} alt="" />
                                </div>
                                <div className="price">
                                ￥{item.price}
                                </div>
                                <div className="title">
                                {item.title}
                                </div>
                                <div className="shop-name">
                                {item.shop}
                                </div>
                                <div className="feature">
                                    {item.isZY ? <span>自营</span> : null}
                                </div>
                            </div>
                        })
                    }
                    

                </div>
            </div>  
        )
    }


    async componentDidMount(){
        let result = await axios.get('http://127.0.0.1:3002/goods');
        //
        // console.log(result);
        this.setState({
            goods: result.data
        })
    }

}
